<template>
	<view class="top">
		<!-- 循环显示车辆信息 -->
		<uni-card v-for="(item, index) in carlist" :key="index"
			style="border-radius: 10px; margin-top: 0px; height: 150px;">
			<view style="display: flex; margin-top: 15px;">
				<image style="height: 50px; width: 50px; border-radius: 50%; margin-right: 10px;"
					src="../../static/images/ly/Letter.jpg">
				</image>
				<view>
					<view style="font-weight: bold; font-size: 18px;">车型：{{ item.carModel }}</view>
					<view style="margin-top: 10px; font-size: 15px;">车牌：{{ item.carNumber }}</view>
				</view>
			</view>
			<u-radio-group style="margin-top: 30px; display: flex; justify-content: space-between;"
				@change="onRadioChange(item)">
				<u-radio :value="item.carNumber" :activeColor="selectedPlate===item.carNumber ? 'red' : 'grey'"
					class="dianji"></u-radio>
			</u-radio-group>
		</uni-card>

		<u-tabbar :value="value6" @change="name => (value6 = name)" :fixed="true" :placeholder="true"
			:safeAreaInsetBottom="true" :border="false">
			<button class="button" type="primary" @click="add">+ 添加车辆</button>
		</u-tabbar>
	</view>
</template>





<script>
	export default {
		data() {
			return {
				item: [],
				userId: 0,
				selectedPlate: '',
				car: {},
				carlist: {},
				value6: '' // tabbar 的值

			};
		},
		onLoad(e) {
			this.userId = uni.getStorageSync("user_id")
			this.item = JSON.parse(decodeURIComponent(e.item));
			console.log(this.item)
			this.list();
		},
		methods: {
			list() {
				let that = this;
				this.$http({
					url: '/api/car/car/list',
					method: 'GET',
					success(res) {
						console.log(res);
						if (res.data.code == 200) {
							that.carlist = res.data.rows;
						}
					}
				});


			},
			onRadioChange(index) {
				console.log(index)
				this.selectedPlate = index.carNumber;
				this.car = index;
				// 获取当前选中的车辆

				console.log('当前选中的车辆信息:', this.car);

				// 你可以在这里执行其他逻辑，比如保存状态到后端等
			},
			add() {
				const additionalData = this.car; // 要添加的新对象数据
				const item = {
					...this.item,
					...additionalData
				}; // 合并对象

				uni.navigateTo({
					url: `/pages/lzx/confirmOrder?item=${encodeURIComponent(JSON.stringify(item))}`
				});
			},
		}
	};
</script>





<style>
	.dianji {
		margin-left: 90%;
		margin-top: -210rpx;
	}

	.top {
		height: 150px;
		background-image: url("../../static/images/ly/组 6.png");
	}

	.button {
		height: 30px;
		width: 250px;
		font-size: 15px;
		background-color: #3486FD;
		border-radius: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 10px;
	}
</style>